package com.sxt.jt808.dto;

import cn.hutool.core.codec.BCD;
import io.netty.buffer.ByteBuf;

/**
 * @Author: 罗林
 * @Date: 2019-12-15
 * @Description:位置上报包
 * @Version: 1.0
 */
public class LocationMsg extends Jt808Msg{
	
	private int alarm; //告警信息 4字节
    private int statusField;//状态 4字节
    private float latitude;//纬度 4字节
    private float longitude;//经度 4字节
    private short elevation;//海拔高度 2字节
    private short speed; //速度 2字节
    private short direction; //方向 2字节
    private String time; //时间 6字节BCD

    // TODO set 和 get 方法
    
	public int getAlarm() {
		return alarm;
	}
	public void setAlarm(int alarm) {
		this.alarm = alarm;
	}
	public int getStatusField() {
		return statusField;
	}
	public void setStatusField(int statusField) {
		this.statusField = statusField;
	}
	public float getLatitude() {
		return latitude;
	}
	public void setLatitude(float latitude) {
		this.latitude = latitude;
	}
	public float getLongitude() {
		return longitude;
	}
	public void setLongitude(float longitude) {
		this.longitude = longitude;
	}
	public short getElevation() {
		return elevation;
	}
	public void setElevation(short elevation) {
		this.elevation = elevation;
	}
	public short getSpeed() {
		return speed;
	}
	public void setSpeed(short speed) {
		this.speed = speed;
	}
	public short getDirection() {
		return direction;
	}
	public void setDirection(short direction) {
		this.direction = direction;
	}
	public String getTime() {
		return time;
	}
	public void setTime(String time) {
		this.time = time;
	}
	
	@Override
	public String toString() {
		return "LocationMsg [alarm=" + alarm + ", statusField=" + statusField + ", latitude=" + latitude
				+ ", longitude=" + longitude + ", elevation=" + elevation + ", speed=" + speed + ", direction="
				+ direction + ", time=" + time + "]";
	}
	/**
     * 	无参构造函数
     * @param raw
     * @return
     */
	public LocationMsg() {
		
	}
	
	/**
     * 	有参构造函数
     * @param byteBuf
     * @return
     */
	public LocationMsg(ByteBuf byteBuf) {
		super(byteBuf);
	}
	
	/**
	 * 	实现父类抽象方法（解析消息体）
	 */
	@Override
	protected void parseBody() {
		ByteBuf bb = this.getMsgBodyByteBuf();
		// 1. byte[0-3] 报警标志(DWORD(32))
		this.setAlarm(bb.readInt());//告警信息 4字节
        this.setStatusField(bb.readInt());//状态 4字节
        this.setLatitude(bb.readUnsignedInt() * 1.0F / 1000000);//纬度 4字节
        this.setLongitude(bb.readUnsignedInt() * 1.0F / 1000000);//经度 4字节
        this.setElevation(bb.readShort());//海拔高度 2字节
        this.setSpeed(bb.readShort());//速度 2字节
        this.setDirection(bb.readShort());//方向 2字节
        // byte[22-x] 时间(BCD[6]) YY-MM-DD-hh-mm-ss
     	// GMT+8 时间，本标准中之后涉及的时间均采用此时区
        byte[] timeBytes = new byte[6];
        bb.getBytes(22, timeBytes);
        this.setTime(BCD.bcdToStr(timeBytes));//时间 BCD[6]
	}
    
}
